package com.hmall.search.controller;


import com.hmall.common.domain.PageDTO;
import com.hmall.search.domin.ItemPageQuery;
import com.hmall.search.domin.po.ItemDoc;
import com.hmall.search.service.ISearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@Api(tags = "搜索相关接口")
@RestController
@RequestMapping("/search")
@RequiredArgsConstructor
public class SearchController {

    private final ISearchService searchService;

    @ApiOperation("搜索商品")
    @GetMapping("/list")
    public PageDTO<ItemDoc> searchPage(ItemPageQuery query) throws IOException {
        PageDTO<ItemDoc> page =  searchService.searchPage(query);
        return page;
    }

    @ApiOperation("自动补全")
    @GetMapping("/suggestion")
    public List<String> suggestion(String key) throws IOException {
        List<String> list = searchService.suggestion(key);
        return list;
    }
}